package StudyCode.Component;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import java.io.File;

/**
 * @author lixiaoyao
 * @date 2018/11/22 0022、下午 1:18
 * @description 文件显示图标
 */
public class FileIconViewer extends FileView {

	private FileFilter fileFilter;
	private Icon icon;

	public FileIconViewer(FileFilter fileFilter, Icon icon) {
		this.fileFilter = fileFilter;
		this.icon = icon;
	}

	public Icon getIcon(File file) {
		if (!file.isDirectory() && fileFilter.accept(file)) {
			return icon;
		}
		return null;
	}

}
